package com.hhit.bigscreenbackmanage.service.impl.tgygl;

import com.hhit.bigscreenbackmanage.dao.tgygl.TTgyglConverterStationMapper;
import com.hhit.bigscreenbackmanage.entity.tgygl.TTgyglConverterStation;
import com.hhit.bigscreenbackmanage.service.tgygl.TTgyglConverterStationService;
import org.seimicrawler.xpath.JXNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author  zhl
 * @Date 2021/7/22
 */
@Service
public class TTgyglConverterStationServiceImpl implements TTgyglConverterStationService {

    @Autowired
    private TTgyglConverterStationMapper tTgyglConverterStationMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return 0;
    }

    @Override
    public int insert(TTgyglConverterStation record) {
        return 0;
    }

    @Override
    public int insertSelective(TTgyglConverterStation record) {
        return 0;
    }

    @Override
    public TTgyglConverterStation selectByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(TTgyglConverterStation record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(TTgyglConverterStation record) {
        return 0;
    }

    @Override
    public int insert(JXNode jxNode, int id) throws Exception {
        List<JXNode> trNodeList = jxNode.sel("//tr");
        trNodeList.forEach(item-> {
            int index = trNodeList.indexOf(item);
            if (index!=0) {
                List<JXNode> tdNodeList = item.sel("//td");
                TTgyglConverterStation  tTgyglConverterStation = new TTgyglConverterStation();

                tTgyglConverterStation.setConstructionStage(tdNodeList.get(0).selOne("//p//text()")==null?"":tdNodeList.get(0).selOne("//p//text()").toString());
                tTgyglConverterStation.setSongduan(tdNodeList.get(1).selOne("//p//text()")==null?"":tdNodeList.get(1).selOne("//p//text()").toString());
                tTgyglConverterStation.setShouduan(tdNodeList.get(2).selOne("//p//text()")==null?"":tdNodeList.get(2).selOne("//p//text()").toString());
                tTgyglConverterStation.setJddbj(tdNodeList.get(3).selOne("//p//text()")==null?"":tdNodeList.get(3).selOne("//p//text()").toString());
                tTgyglConverterStation.setRemarks(tdNodeList.get(4).selOne("//p//text()")==null?"":tdNodeList.get(4).selOne("//p//text()").toString());
                tTgyglConverterStation.setFileId(id);
                System.out.println(tTgyglConverterStation);
                tTgyglConverterStationMapper.insert(tTgyglConverterStation);
            }
            System.out.println(item);
        });
        return 0;
    }

    @Override
    public List<TTgyglConverterStation> selectListByFileId(Integer fileId) {
        List<TTgyglConverterStation> resulList = null;
        TTgyglConverterStation tTgyglConverterStation = new TTgyglConverterStation();
        tTgyglConverterStation.setFileId(fileId);
        try {
            resulList = tTgyglConverterStationMapper.selectByBean(tTgyglConverterStation);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return resulList;
    }
}
